package com.laizhenghua.wxstub.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.laizhenghua.wxstub.service.MessageService;
import com.laizhenghua.wxstub.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @author: laizhenghua
 * @date: 2022/8/31 21:23
 */
@Api(tags = "APP-附加消息")
@RestController
@RequestMapping(RestURL.MESSAGE_URL)
public class MessageController {

    @Autowired
    private MessageService messageService;

    @ApiOperation(value = "接收：接收微信推送的消息", notes = "api/message/callback/notify", response = R.class)
    @RequestMapping(value = "/callback/notify", method = RequestMethod.GET)
    public R callbackNotify(
            @ApiParam(value = "微信加密签名", required = true) @RequestParam("signature") String signature,
            @ApiParam(value = "时间戳", required = true) @RequestParam("timestamp") String timestamp,
            @ApiParam(value = "随机数", required = true) @RequestParam("nonce") String nonce,
            @ApiParam(value = "随机字符串", required = true) @RequestParam("echostr") String echostr) {
        return R.ok().put("data", messageService.callbackNotify(signature, timestamp, nonce, echostr));
    }

    @ApiOperation(value = "获取：根据城市名称获取天气信息", notes = "api/message/weather/info", response = R.class)
    @RequestMapping(value = "/weather/info", method = RequestMethod.GET)
    public R getWeatherInfo(@ApiParam(value = "城市名称(不带市如武汉)", required = true) @RequestParam("city") String city) {
        JSONObject response = messageService.getWeatherInfo(city);
        return R.ok().put("data", response);
    }

    @ApiOperation(value = "获取：获取土味情话", notes = "api/message/love/content", response = R.class)
    @RequestMapping(value = "/love/content", method = RequestMethod.GET)
    public R getLoveContent() {
        return R.ok().put("data", messageService.getLoveContent());
    }

    @ApiOperation(value = "获取：根据城市名称获取疫情信息", notes = "api/message/yq/list", response = R.class)
    @RequestMapping(value = "/yq/list", method = RequestMethod.GET)
    public R getYqList(
            @ApiParam(value = "省份", required = true) @RequestParam("province") String province,
            @ApiParam(value = "市级", required = true) @RequestParam("city") String city) {
        String response = messageService.getYqList(province, city);
        return R.ok().put("data", response);
    }

    @ApiOperation(value = "获取：获取微博热搜", notes = "api/message/wb/host", response = JSONArray.class)
    @RequestMapping(value = "/wb/host", method = RequestMethod.GET)
    public R getWbHost(@ApiParam("热搜数量(小于10)") @RequestParam(value = "size", required = false) Integer size) {
        size = size == null ? 10 : size;
        JSONArray response = messageService.getWbHost(size);
        return R.ok().put("data", response);
    }

    @ApiOperation(value = "获取：获取CSDN热搜文章", notes = "api/message/csdn/host", response = JSONArray.class)
    @RequestMapping(value = "/csdn/host", method = RequestMethod.GET)
    public R getCsdnHost(@ApiParam("热搜数量(小于10)") @RequestParam(value = "size", required = false) Integer size) {
        size = size == null ? 10 : size;
        JSONArray response = messageService.getCsdnHost(size);
        return R.ok().put("data", response);
    }

    @ApiOperation(value = "获取：随机获取网易云音乐热评", notes = "api/message/wyy/content", response = JSONArray.class)
    @RequestMapping(value = "/wyy/content", method = RequestMethod.GET)
    public R getWyyContent() {
        String content = messageService.getWyyContent();
        return R.ok().put("data", content);
    }
}
